/**
 * Copyright(c) 2013 Jade Techonologies Co., Ltd.
 *
 * History:
 *   13-7-11 上午9:37 Created by sky
 */
package com.jade.modules.message.sms;

import java.io.Serializable;
import java.util.Date;

import com.jade.framework.base.lang.OctetString;

/**
 * 抽象的短信消息。
 *
 * @author sky
 * @version 1.0 13-7-11 上午9:37
 */
public class SmsMessage
        implements Serializable
{
    private String messageId;
    private String from;
    private String[] to;
    private int priority;
    private byte format;
    private OctetString content;
    private Date atTime;
    private Date validTime;
    private byte reportFlag;
    private byte udhi = 0;
    private int packetNumber = 1;
    private int packetIndex = 1;

    public String getMessageId()
    {
        return messageId;
    }

    public void setMessageId(String messageId)
    {
        this.messageId = messageId;
    }

    public String getFrom()
    {
        return from;
    }

    public void setFrom(String from)
    {
        this.from = from;
    }

    public String[] getTo()
    {
        return to;
    }

    public void setTo(String[] to)
    {
        this.to = to;
    }

    public void setTo(String to)
    {
        this.to = new String[]{to};
    }

    public int getReceiverCount()
    {
        return to == null ? 0 : to.length;
    }

    public int getPriority()
    {
        return priority;
    }

    public void setPriority(int priority)
    {
        this.priority = priority;
    }

    public byte getFormat()
    {
        return format;
    }

    public void setFormat(byte format)
    {
        this.format = format;
    }

    public OctetString getContent()
    {
        return content;
    }

    public void setContent(OctetString content)
    {
        this.content = content;
    }

    /**
     * 设置短信内容.
     *
     * @param content 短信的内容.
     */
    public void setContent(byte[] content)
    {
        setContent(new OctetString(content));
    }

    public void setContent(String content)
    {
        setContent(SmsUtils.toBytes(content, getFormat()));
    }

    public byte[] getContentBytes()
    {
        return content != null ? content.getBytes() : null;
    }

    public String getContentString()
    {
        byte[] bytes = getContentBytes();
        return SmsUtils.toString(bytes, getFormat());
    }

    public int getContentLength()
    {
        if (content == null) {
            return 0;
        }
        if (format == SmsConstants.FORMAT_BINARY) {
            return content.length();
        }
        else {
            return getContentString().length();
        }
    }

    public Date getAtTime()
    {
        return atTime;
    }

    public void setAtTime(Date atTime)
    {
        this.atTime = atTime;
    }

    public Date getValidTime()
    {
        return validTime;
    }

    public void setValidTime(Date validTime)
    {
        this.validTime = validTime;
    }

    public byte getReportFlag()
    {
        return reportFlag;
    }

    public void setReportFlag(byte reportFlag)
    {
        this.reportFlag = reportFlag;
    }

    public byte getUdhi()
    {
        return udhi;
    }

    public void setUdhi(byte udhi)
    {
        this.udhi = udhi;
    }

    public int getPacketNumber()
    {
        return packetNumber;
    }

    public void setPacketNumber(int packetNumber)
    {
        this.packetNumber = packetNumber;
    }

    public int getPacketIndex()
    {
        return packetIndex;
    }

    public void setPacketIndex(int packetIndex)
    {
        this.packetIndex = packetIndex;
    }
}
